//
//  AXFPayMentCell.m
//  BEEQUICK
//
//  Created by HH on 16/11/24.
//  Copyright © 2016年 SevenGroup. All rights reserved.
//

#import "AXFPayMentCell.h"

@interface AXFPayMentCell ()

@property (nonatomic,weak) UIImageView *iconView;
@property (nonatomic,weak) UILabel *nameLabel;
@property (nonatomic,weak)  UIButton *selectedButton;
@end

@implementation AXFPayMentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(NSDictionary *)model
{
    _model = model;
    
    _iconView.image = [UIImage imageNamed:model[@"img"]];
    _nameLabel.text = model[@"name"];
    
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI
{
    UIImageView *iconView = [[UIImageView alloc] init];
    
    iconView.image = [UIImage imageNamed:@"v2_selected"];
    
    [self.contentView addSubview:iconView];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    
    nameLabel.text = @"支付宝支付";
    
    nameLabel.font = [UIFont systemFontOfSize:10];
    
    [self.contentView addSubview:nameLabel];
    
    UIButton *selectedBtn = [[UIButton alloc] init];
    [selectedBtn setImage:[UIImage imageNamed:@"v2_noselected"] forState:UIControlStateNormal];
    [selectedBtn setImage:[UIImage imageNamed:@"v2_selected"] forState:UIControlStateSelected];
    self.selectedButton = selectedBtn;
    
    [self.contentView addSubview:selectedBtn];
    
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.equalTo(self.contentView);
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(5);
        make.centerY.equalTo(self.contentView);
    }];
    
    [selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-8);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    // 关联
    _iconView = iconView;
    _nameLabel = nameLabel;
    //    _selectedButton = selectedBtn;
    //    self.selectBtn = selectedBtn;
}

- (void)setIndex:(BOOL)index
{
    _index = index;
    
    self.selectedButton.selected = index;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
